package org.spring.blog.controller.portal;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.spring.blog.interceptor.CheckToolFrequentCommit;
import org.spring.blog.pojo.Comment;
import org.spring.blog.response.ResponseResult;
import org.spring.blog.response.ResponseState;
import org.spring.blog.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/portal/comment")
public class CommentPortalApi {

    @Autowired
    private ICommentService commentService;

    /**
     * 添加评论
     *
     * @param _comment 评论对象
     * @return 自定义返回对象
     */
    @ApiOperation("添加评论")
    @ApiResponses({
            @ApiResponse(code = ResponseState.user_not_login_code, message = ResponseState.user_not_login_message),
            @ApiResponse(code = ResponseState.input_data_not_complete_code, message = ResponseState.input_data_not_complete_message),
            @ApiResponse(code = ResponseState.data_not_have_code, message = ResponseState.data_not_have_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @CheckToolFrequentCommit
    @PostMapping
    public ResponseResult insert(@RequestBody Comment _comment) {
        return commentService.insert(_comment);
    }


    /**
     * 删除评论
     *
     * @param _id 评论id
     * @return 自定义返回对象
     */
    @ApiOperation("删除评论")
    @ApiResponses({
            @ApiResponse(code = ResponseState.user_not_login_code, message = ResponseState.user_not_login_message),
            @ApiResponse(code = ResponseState.data_not_have_code, message = ResponseState.data_not_have_message),
            @ApiResponse(code = ResponseState.no_power_code, message = ResponseState.no_power_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @DeleteMapping("/{commentId}")
    public ResponseResult delete(@PathVariable("commentId") String _id) {
        return commentService.delete(_id);
    }

    /**
     * 获取文章评论列表
     *
     * @param articleId 文章id
     * @return 自定义返回对象
     */
    @ApiOperation("获取文章评论列表")
    @ApiResponses(@ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message))
    @GetMapping("/list/{page}/{size}/{articleId}")
    public ResponseResult list(@PathVariable("articleId") String articleId,
                               @PathVariable int page,
                               @PathVariable int size) {

        return commentService.list(articleId, page, size);
    }
}
